package name.file.wwplusfastfood;

import com.bappi.custom.activities.CustomActivity;
import com.bappi.utils.HttpUtils;
import com.bappi.utils.Utils;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;

public class RestaurantDetailsActivity extends CustomActivity {

	private static final String HTML_FILE_LOCATION = "file:///android_asset/htmls/%s.htm";
	public static final String KEY_ID = "KEY_ID";
	private TextView titleView;
	private WebView mWebView;
	private Button addOrRemoveFavorites;
//	private Button buttonNearMe;
	private ListItem listItem;
	

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.layout_restaurant_details);
		titleView = (TextView)findViewById(R.id.title_view);
		addOrRemoveFavorites = (Button)findViewById(R.id.button_add_to_favorites);
//		buttonNearMe = (Button)findViewById(R.id.button_near_me);
		listItem = TabsController.getRestaurent(getIntent().getIntExtra(KEY_ID, 0));
		titleView.setText(listItem.getTitle());
		mWebView = (WebView) findViewById(R.id.web_view); // This is the id you
														// gave
		// to the WebView in the main.xml
		mWebView.getSettings().setJavaScriptEnabled(true);
		mWebView.getSettings().setSupportZoom(true); // Zoom Control on web (You
														// don't need this
		// if ROM supports Multi-Touch
		mWebView.getSettings().setBuiltInZoomControls(true); // Enable
																// Multitouch if
																// supported by
																// ROM

		// Load URL
		
		
		mWebView.loadUrl(String.format(HTML_FILE_LOCATION, listItem.getHtmlName()));
		if(listItem.isFavorite()){
			addOrRemoveFavorites.setText("Remove from Favorites");
		}else{
			addOrRemoveFavorites.setText("Add to Favorites");
		}
		addOrRemoveFavorites.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				
				if(listItem.isFavorite()){
					TabsController.removeFromFavorite(listItem);
					addOrRemoveFavorites.setText("Add to Favorites");
				}else{
					TabsController.addToFavorite(listItem);
					addOrRemoveFavorites.setText("Remove from Favorites");
					
				}
				
			}
		});
//		buttonNearMe.setOnClickListener(new View.OnClickListener() {
//			public void onClick(View v) {
//				showMapCheckingInternetConnection();
//			}
//		});
	}
	
//	private void showMapCheckingInternetConnection(){
//		new AsyncTask<String, String, String>() {
//			private boolean isOnline;
//			protected String doInBackground(String... arg0) {
//				try {
//					isOnline = HttpUtils.isDeviceOnline(getParent());
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//				return null;
//			}
//
//			protected void onPostExecute(String unused) {
//				try {
//					if(isOnline){
//						Intent intent = new Intent(getParent(),MapViewerActivity.class);
//						intent.putExtra(RestaurantDetailsActivity.KEY_ID,
//								listItem.getId());
////						startActivity(intent);
//						pushIntnet(intent);
//					}else{
//						Utils.showAlertMessage(getParent(), "Please go online for this service!");
//					}
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//		}.execute();
//	}
}